package com.huawei.updatesdk.service.otaupdate;

import android.content.Context;
import java.text.DecimalFormat;
import java.text.NumberFormat;

public class h {
    public static int a(int i, int i2) {
        if (i2 <= 0) {
            return 0;
        }
        int round = (int) Math.round((((double) i) / ((double) i2)) * 100.0d);
        return round <= 100 ? round : 100;
    }

    public static String a(int i) {
        NumberFormat percentInstance = NumberFormat.getPercentInstance();
        double d = (double) (((float) i) / 100.0f);
        percentInstance.setMinimumFractionDigits(0);
        return percentInstance.format(d);
    }

    public static String a(Context context, long j) {
        if (j == 0) {
            return context.getString(f.b(context, "upsdk_storage_utils"), new Object[]{"0"});
        }
        DecimalFormat decimalFormat = null;
        String str = "";
        if (j > 104857) {
            decimalFormat = new DecimalFormat("###.#");
        } else if (j > 10485) {
            decimalFormat = new DecimalFormat("###.##");
        }
        if (decimalFormat != null) {
            double d = ((double) j) / 1048576.0d;
            return context.getString(f.b(context, "upsdk_storage_utils"), new Object[]{decimalFormat.format(d)});
        }
        return context.getString(f.b(context, "upsdk_storage_utils"), new Object[]{"0.01"});
    }
}
